package cn.funeralobjects.util.converter;

import cn.funeralobjects.util.CollectionUtils;

import java.util.List;

/**
 * 默认的List字串对数据库字串的转换器
 *
 * @author FuneralObjects
 * Create date: 2020/4/14 5:49 PM
 */
public class DefaultListStringConverter extends BaseListConverter<String, String> {

    protected static final String SPLIT_DELIMITER = "\\u007C";
    protected static final String DELIMITER = "|";
    protected static final String NULL_VALUE = "!--";

    @Override
    public String convertToDatabaseColumn(List<String> attribute) {
        return attribute == null ? NULL_VALUE : CollectionUtils.join(attribute, DELIMITER);
    }

    @Override
    public List<String> convertToEntityAttribute(String dbData) {
        return CollectionUtils.split(dbData, SPLIT_DELIMITER);
    }
}
